﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Highscores
{
    public partial class Highscores : Form
    {
        public Highscores()
        {
            InitializeComponent();

            InitializeList();

        }
        public void InitializeList()
        {
            AddScore("A", 5000);
            AddScore("B", 3000);
            AddScore("C", 7500);
            AddScore("D", 500);

            //Inlezen Highscores file

            ColumnHeaderAutoResizeStyle ARCContent = ColumnHeaderAutoResizeStyle.ColumnContent;
            ColumnHeaderAutoResizeStyle ARHSize = ColumnHeaderAutoResizeStyle.HeaderSize;
            ColumnHeaderAutoResizeStyle resize;

            int test = ARHSize.CompareTo(ARCContent);
            if (test < 0)
                resize = ARHSize;
            else
                resize = ARCContent;
            

            lstScores.AutoResizeColumns(resize);
        }

        public void AddScore(string name, uint score)
        {
            string SCORE = Convert.ToString(score);
            string DATE = DateTime.Now.ToString();
            string[] item = {name, SCORE, DATE};

            ListViewItem lviNAME = new ListViewItem();
            lviNAME.Text = name;

            ListViewItem.ListViewSubItem lvsiSCORE = new ListViewItem.ListViewSubItem();
            lvsiSCORE.Text = SCORE;
            lviNAME.SubItems.Add(lvsiSCORE);

            ListViewItem.ListViewSubItem lvsiDATE = new ListViewItem.ListViewSubItem();
            lvsiDATE.Text = DATE;
            lviNAME.SubItems.Add(lvsiDATE);

            lstScores.Items.Add(lviNAME);

            lstScores.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
        }

        private void lstScores_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            ListViewSorter Sorter = new ListViewSorter();
            lstScores.ListViewItemSorter = Sorter;

            if (!(lstScores.ListViewItemSorter is ListViewSorter))
                return;
            Sorter = (ListViewSorter)lstScores.ListViewItemSorter;

            //if (Sorter.LastSort == e.Column)
            //{
                if (lstScores.Sorting == SortOrder.Ascending)
                    lstScores.Sorting = SortOrder.Descending;
                else
                    lstScores.Sorting = SortOrder.Ascending;
           // }
           // else
            // {
            //    lstScores.Sorting = SortOrder.Descending;
           // }
            Sorter.ByColumn = e.Column;

            lstScores.Sort();
        }

    }
}
